package org.particlethink.controller;


import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestHeader;
import org.springframework.web.bind.annotation.RestController;

import java.util.*;

@RestController
public class TestController {


    private static final List<String> MOCK_DICT_DATA = Arrays.asList("土建", "安装(水、电)", "装饰", "临建", "安全生产费", "文明施工费", "周转材料", "购置资产", "冬施费用");

    @PostMapping("/system/dict/type/find")
    public Map<String, Object> getDictionaries() {

        Map<String, Object> dataPart = new HashMap<>();
        dataPart.put("types", MOCK_DICT_DATA);

        Map<String, Object> response = new HashMap<>();
        response.put("msg", "Success");
        response.put("code", 200);
        response.put("data", dataPart);

        return response;
    }

    @PostMapping("/material/typeTree")
    public Map<String, Object> getMajorTypes(@RequestHeader("Authorization") String bearerToken) {
        List<MajorType> list = new ArrayList<>();
        list.add(new MajorType("黑色及有色金属", new ArrayList<>(Arrays.asList(new MinorType("钢筋"), new MinorType("钢丝"), new MinorType("钢丝绳")))));
        list.add(new MajorType("橡胶、塑料及非金属", new ArrayList<>(Arrays.asList(new MinorType("橡胶桶"), new MinorType("橡胶板"), new MinorType("橡胶条")))));
        Map<String, Object> response = new HashMap<>();
        response.put("code", 200);
        response.put("data", list);
        return response;
    }

    public static class MajorType {
        private String majorName;
        private List<MinorType> minorType;

        public MajorType(String majorName, List<MinorType> minorType) {
            this.majorName = majorName;
            this.minorType = minorType;
        }

        public MajorType() {
        }

        public String getMajorName() {
            return majorName;
        }

        public void setMajorName(String majorName) {
            this.majorName = majorName;
        }

        public List<MinorType> getMinorType() {
            return minorType;
        }

        public void setMinorType(List<MinorType> minorType) {
            this.minorType = minorType;
        }
    }


    @PostMapping("/material/details/list")
    public Map<String, Object> getMaterials(@RequestBody List<String> categories, @RequestHeader("Authorization") String bearerToken) {
        List<Material> list = new ArrayList<>();
        list.add(new Material(1, "40mm圆钢", "M-001-010001", "钢筋", "", "$40", "Q235", "吨", "国标", ""));
        list.add(new Material(2, "10mm圆钢", "M-001-010002", "钢筋", "", "$10", "Q235", "吨", "国标", ""));
        list.add(new Material(3, "1.0钢丝", "M-002-010001", "钢丝", "", "$10", "Q235", "吨", "国标", ""));
        list.add(new Material(4, "0.5钢丝", "M-002-010002", "钢丝", "", "$10", "Q235", "吨", "国标", ""));


        Map<String, Object> response = new HashMap<>();
        response.put("code", 200);
        response.put("data", list);
        return response;
    }

    @PostMapping("/material/api/projects")
    public Map<String, Object> getProjects() {
        List<Data> dataList = new ArrayList<>();
        dataList.add(new Data(1, "", "天祥广场D5项目", "", "", "", "四川省成都市高新区天府二街天祥广场", "四川分公司", ""));
        dataList.add(new Data(2, "", "河北工业大学大门项目", "", "", "", "天津市北辰区河北工业大学", "河北分公司", ""));


        Map<String, Object> response = new HashMap<>();
        response.put("data", dataList);
        response.put("code", 200);
        return response;
    }


    @PostMapping("/api/suppliers")
    public Map<String, Object> getSuppliers() {
        // Generate test data for Response
        Row row = new Row();

        // populate row fields
        row.setId(1);
        row.setName("Test Supplier");
        row.setResourceId("test-resourceId");
        row.setAddress("Test Address");
        row.setPhone("123456789");

        Row row2 = new Row();

        // populate row fields
        row2.setId(2);
        row2.setName("Test Supplier2");
        row2.setResourceId("test-resourceId");
        row2.setAddress("Test Address");
        row2.setPhone("123456789");

        Map<String, Object> responseMap = new HashMap<>();
        // populate response fields
        responseMap.put("total", 1);
        responseMap.put("code", 200);
        responseMap.put("msg", "Success");
        responseMap.put("rows", Arrays.asList(row, row2));

        return responseMap;
    }

    public static class Row {
        private Integer id;
        private String resourceId;
        private String name;
        private String address;
        private String phone;

        public String getName() {
            return name;
        }

        public void setName(String name) {
            this.name = name;
        }

        public Integer getId() {
            return id;
        }

        public void setId(Integer id) {
            this.id = id;
        }

        public String getResourceId() {
            return resourceId;
        }

        public void setResourceId(String resourceId) {
            this.resourceId = resourceId;
        }

        public String getAddress() {
            return address;
        }

        public void setAddress(String address) {
            this.address = address;
        }

        public String getPhone() {
            return phone;
        }

        public void setPhone(String phone) {
            this.phone = phone;
        }
    }

    public static class Data {
        private Integer id;
        private String resourceId;
        private String name;
        private String projectCode;
        private String province;
        private String city;
        private String address;
        private String managementLevel;
        private String remarks;

        public Data(Integer id, String resourceId, String name, String projectCode, String province, String city, String address, String managementLevel, String remarks) {
            this.id = id;
            this.resourceId = resourceId;
            this.name = name;
            this.projectCode = projectCode;
            this.province = province;
            this.city = city;
            this.address = address;
            this.managementLevel = managementLevel;
            this.remarks = remarks;
        }

        public Data() {
        }

        public Integer getId() {
            return id;
        }

        public void setId(Integer id) {
            this.id = id;
        }

        public String getResourceId() {
            return resourceId;
        }

        public void setResourceId(String resourceId) {
            this.resourceId = resourceId;
        }

        public String getName() {
            return name;
        }

        public void setName(String name) {
            this.name = name;
        }

        public String getProjectCode() {
            return projectCode;
        }

        public void setProjectCode(String projectCode) {
            this.projectCode = projectCode;
        }

        public String getProvince() {
            return province;
        }

        public void setProvince(String province) {
            this.province = province;
        }

        public String getCity() {
            return city;
        }

        public void setCity(String city) {
            this.city = city;
        }

        public String getAddress() {
            return address;
        }

        public void setAddress(String address) {
            this.address = address;
        }

        public String getManagementLevel() {
            return managementLevel;
        }

        public void setManagementLevel(String managementLevel) {
            this.managementLevel = managementLevel;
        }

        public String getRemarks() {
            return remarks;
        }

        public void setRemarks(String remarks) {
            this.remarks = remarks;
        }
    }

    public static class MinorType {
        private String minorName;

        public MinorType() {
        }

        public MinorType(String minorName) {
            this.minorName = minorName;
        }

        public String getMinorName() {
            return minorName;
        }

        public void setMinorName(String minorName) {
            this.minorName = minorName;
        }
    }

    public static class Material {
        private Integer id;
        private String name;
        private String code;
        private String materialCategory;
        private String materialDetail;
        private String specification;
        private String model;
        private String unit;
        private String qualityStandard;
        private String description;

        public Material() {
        }

        public Material(Integer id, String name, String code, String materialCategory, String materialDetail, String specification, String model, String unit, String qualityStandard, String description) {
            this.id = id;
            this.name = name;
            this.code = code;
            this.materialCategory = materialCategory;
            this.materialDetail = materialDetail;
            this.specification = specification;
            this.model = model;
            this.unit = unit;
            this.qualityStandard = qualityStandard;
            this.description = description;
        }

        public Integer getId() {
            return id;
        }

        public void setId(Integer id) {
            this.id = id;
        }

        public String getName() {
            return name;
        }

        public void setName(String name) {
            this.name = name;
        }

        public String getCode() {
            return code;
        }

        public void setCode(String code) {
            this.code = code;
        }

        public String getMaterialCategory() {
            return materialCategory;
        }

        public void setMaterialCategory(String materialCategory) {
            this.materialCategory = materialCategory;
        }

        public String getMaterialDetail() {
            return materialDetail;
        }

        public void setMaterialDetail(String materialDetail) {
            this.materialDetail = materialDetail;
        }

        public String getSpecification() {
            return specification;
        }

        public void setSpecification(String specification) {
            this.specification = specification;
        }

        public String getModel() {
            return model;
        }

        public void setModel(String model) {
            this.model = model;
        }

        public String getUnit() {
            return unit;
        }

        public void setUnit(String unit) {
            this.unit = unit;
        }

        public String getQualityStandard() {
            return qualityStandard;
        }

        public void setQualityStandard(String qualityStandard) {
            this.qualityStandard = qualityStandard;
        }

        public String getDescription() {
            return description;
        }

        public void setDescription(String description) {
            this.description = description;
        }
    }
}
